//
//  ZZXLoactionThirdViewController.m
//  Travel
//
//  Created by dllo on 15/11/30.
//  Copyright © 2015年 doll. All rights reserved.
//

#import "ZZXLoactionThirdViewController.h"
#import "ZZXstrategryModel.h"
#import "KHHTravelNotesPageUserTableViewCell.h"
#import "KHHTravelNotesDetailPageTableViewCell.h"


@interface ZZXLoactionThirdViewController ()<UITableViewDelegate, UITableViewDataSource>

@property (nonatomic, strong)UITableView *tableView;
@property (nonatomic, strong)ZZXstrategryModel *modelAllData;
@property (nonatomic, strong)ZZXstrategryModel *modelOwner; //用户信息
@property (nonatomic, strong)NSMutableArray *modelRecordsArr; // 游记信息


@end

@implementation ZZXLoactionThirdViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    [self addScreenEdgePan];
    //小菊花
    [CXLoadMBProgress loadMBProgress:self.view];
//    [self loadMBProgress];
    //左按钮
    
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithImage:[[UIImage imageNamed:@"leftBack"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] style:UIBarButtonItemStylePlain target:self action:@selector(backToLast)];
    [self getData];
    
}

- (void)getData
{
    NSString *url = [NSString stringWithFormat:@"http://app6.117go.com/demo27/php/formAction.php?recType=0&id1=508277&id2=1&submit=getATour2&tourid=%@&v=i6.4.2&vc=AppStore&vd=b3c1b4cf8b498fb8&lang=zh-Hans&verify=70b2429e21d1a72d46a3d799872525fd", self.listID];
    [CXNetHandle getUrl:url cookie:nil result:^(id result) {
        self.modelAllData = [[ZZXstrategryModel alloc]init];
        [self.modelAllData setValuesForKeysWithDictionary:result[@"obj"]];
        self.modelRecordsArr = [NSMutableArray array];
        self.modelRecordsArr = [ZZXstrategryModel  transformWithArray: result[@"obj"][@"records"]];
        
        self.modelOwner = [[ZZXstrategryModel alloc]init];
        [self.modelOwner setValuesForKeysWithDictionary:result[@"obj"][@"owner"]];
        
        [CXLoadMBProgress removeMBProgress:self.view];
//        [self.hud removeFromSuperview];
        [self createTableView];
    }];
    
    }
    

#pragma mark - 创建tableView
- (void)createTableView
{
    self.tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height) style:UITableViewStylePlain];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    [self.view addSubview:self.tableView];
   
//    [[self class]BoolIsNight:self.tableView];
}

#pragma mark - 按钮触发方法
- (void)backToLast
{
    [self.navigationController popViewControllerAnimated:YES];
}

#pragma mark - 分区数
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 2;
}


#pragma mark - 行数
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (section == 0) {
        return 1;
    }
    else
    {
        return self.modelRecordsArr.count;
    }
}
//
#pragma mark - cell赋值
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    
//    
    if (indexPath.section == 1) {
       KHHTravelNotesDetailPageTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
        if (!cell) {
            cell = [[KHHTravelNotesDetailPageTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
        }
        [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
        cell.backgroundColor = [UIColor colorWithRed:0.98 green:0.97 blue:0.93 alpha:1];
        cell.modelRecords = self.modelRecordsArr[indexPath.row];
        
        return cell;
    }
    else
    {
        KHHTravelNotesPageUserTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"user"];
        if (!cell) {
            cell = [[KHHTravelNotesPageUserTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"user"];
        }
        [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
        cell.backgroundColor = [UIColor colorWithRed:0.98 green:0.97 blue:0.93 alpha:1];
        cell.modelOwner = self.modelOwner;
        cell.modelAllData = self.modelAllData;
    

        cell.modelRecords = self.modelRecordsArr[indexPath.row];
        return cell;
    }
    
}


#pragma mark - 行高
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    if (indexPath.section == 0) {
        return 60 + (self.view.frame.size.width - 20) / 8 + 10 + 10 + 30 + 50 + 20;
    }
    else{
        ZZXstrategryModel *tempModel = self.modelRecordsArr[indexPath.row];
        
        //标题高度
        CGFloat h = [[self class]heightWithText:tempModel.words fontSize:15 Width:CWIDTH - 40];
        
        
        if (h!=0 ) {
            return 255 + 10 + h + 10 + 15 + 10 + 20;
            
        }
        else
        {
            
            return 10 + h + 10 + 15 + 10 + 20;
        }
    }
}


//边缘拖拽
#pragma mark-滑动手势1
- (void)addScreenEdgePan
{
    UIScreenEdgePanGestureRecognizer *screenEdgePan = [[UIScreenEdgePanGestureRecognizer alloc] initWithTarget:self action:@selector(presentLeftMenuViewController:)];
    screenEdgePan.edges = UIRectEdgeLeft;
    [self.view addGestureRecognizer:screenEdgePan];
    [self.tableView addGestureRecognizer:screenEdgePan];
   
}
#pragma mark-滑动手势2
-(void)presentLeftMenuViewController:(UIScreenEdgePanGestureRecognizer *)edge
{
    [self.navigationController popViewControllerAnimated:YES];
    
    
}








- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
